package classes;

import com.mysql.jdbc.Connection;
import Servlet.dataBaseController;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Brian
 */
public class Reports {
    private static Connection con=null;
    private static ResultSet rs=null;
    public Reports()
    {}
    public static void getConnection(String query) throws SQLException
    {
        try{
            con=dataBaseController.getConnection();
        try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Reports.class.getName()).log(Level.SEVERE, null, ex);
            }
            Statement st = (Statement) con.createStatement();
            rs=st.executeQuery(query);
            
//            st.close();
//            con.close();
        }
        catch(SQLException e){
            e.printStackTrace();
        }
    }
    
    public static ArrayList getResults(int... column)
    {
        ArrayList<String[]> al= new ArrayList<String[]>();
        try{
            while(rs.next())
            {
                String[] temp=new String[column.length];
                for(int i=0;i<temp.length;i++)
                {
                      temp[i]=rs.getString(column[i]);
                }
                al.add(temp);
            }
        }catch (SQLException e) {
            e.printStackTrace();
        }
        return al;
    }

}
